var PlayLayer = cc.Layer.extend({ //添加一个层
	
	bgSprite:null, //背景
	
	SushiSprites:null, //图层精灵数组
	
	ctor:function () {
		
		this._super();
		this.SushiSprites = [];
		
		var size = cc.winSize;

		// add bg
		this.bgSprite = new cc.Sprite(res.BackGround_png); //背景精灵
		this.bgSprite.attr({
			x: size.width / 2,
			y: size.height / 2,
			//scale: 0.5,
			rotation: 0 //翻转 ，rotation: 180 表示翻转180度
		});
		this.addChild(this.bgSprite, 0);
//		this.addSushi();
		
		this.schedule(this.update,1,16*1024,1); //创建一个定时器，
		
		return true;
	},
	
	update : function() {
		this.addSushi();
		this.removeSushi();
	},
	
	removeSushi : function() {
	    //移除到屏幕底部的sushi
	    for (var i = 0; i < this.SushiSprites.length; i++) {
	        cc.log("removeSushi.........");
	        if(0 == this.SushiSprites[i].y) {
	            cc.log("==============remove:"+i);
	            this.SushiSprites[i].removeFromParent();
	            this.SushiSprites[i] = undefined;
	            this.SushiSprites.splice(i,1);
	            i= i-1;
	        }
	    }
	},
	
	addSushi : function() {
//		var sushi = new cc.Sprite(res.Sushi_png); //根据图片创建一个精灵
		var sushi = new SushiSprite(res.Sushi_png)
		var size = cc.winSize;

		var x = sushi.width/2+size.width/2*cc.random0To1(); //出现位置为随机横轴X
		sushi.attr({ //添加横纵坐标属性
			x: x,
			y:size.height - 30
		});

		this.addChild(sushi,5);
		this.SushiSprites.push(sushi);
		
		var dorpAction = cc.MoveTo.create(4, cc.p(sushi.x,-30));//添加一个移动控制
		sushi.runAction(dorpAction);//跑起来
	}
});

var PlayScene = cc.Scene.extend({
	onEnter:function () {
		this._super();
		var layer = new PlayLayer();
		this.addChild(layer);
	}
});